#ifndef SPECTRUMVIEW_H
#define SPECTRUMVIEW_H

#include <QtGui>
#include <QWidget>
#include <qwt_plot.h>
#include "PreciseSpectrum.h"

class SpectrumView: public QWidget {
    Q_OBJECT
public:
    SpectrumView(const QColor&, QWidget*);
    void toPdf();
    void copy();
    void distract();
    bool loadFile(const QString& fileName);
    bool saveAs();
    inline QString userFriendlyCurrentFile() const {
        return strippedName(curFile);
    }
    inline QString currentFile() const {
        return curFile;
    }
    inline const QSharedPointer<CommonOptions> commonOptions() const {
        return spectrum.isNull()? QSharedPointer<CommonOptions>(): spectrum->commonOptions();
    }
    void setBackgroundColor(const QColor& color);
protected:
    void closeEvent(QCloseEvent* event);
private:
    QString curFile;
    bool isUntitled;
    QSharedPointer<PreciseSpectrum> spectrum;
    QwtPlot* firstCollector;
    QwtPlot* secondCollector;

    bool distract(const QSharedPointer<PreciseSpectrum>& spec);
    bool saveFile(const QString& fileName);
    bool maybeSave();
    void setCurrentFile(const QString& fileName);
    QString strippedName(const QString& fullFileName) const;
    bool serialize(QTextStream& destination) const;
    void documentWasModified();
signals:
    void copyAvailable(bool);
};

#endif // SPECTRUMVIEW_H
